package me.shibor.study.javaSE.thread;

public class DemoRunnable {

	public static void main(String[] args) {
		
		//new TestRunnable();
		new Thread(new TestRunnable(), "new 试试").start();
		
        try {
            for(int i = 5; i > 0; i--) {
                System.out.println("Main Thread: " + i + Thread.currentThread().getName());
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
           System.out.println("Main thread interrupted.");
        }
        System.out.println("Main thread exiting.");

	}

	
}

class TestRunnable implements Runnable {

	Thread t;
//
//	public TestRunnable() {
//		t = new Thread(this, "Demo Thread");
//		System.out.println("Child thread: " + t);
//		t.start(); // Start the thread
//	}

	public void run() {

		try {
			for (int i = 5; i > 0; i--) {
				System.out.println("Child Thread: " + i + Thread.currentThread().getName());
				Thread.sleep(500);
			}
		} catch (InterruptedException e) {
			System.out.println("Child interrupted.");
			e.printStackTrace();
		}

		System.out.println("Exiting child thread.");
	}

}

